// pages/paymentSuccess/paymentSuccess.js
let app = getApp();
import util from '../../../utils/util.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    'type':'people',
    'id': 0,
    'pid': 0,
    'modelConsole': false,
    'Img_product':'https://www.zhenlvw.com/images/xiao/share2.jpg'
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let type = options.type
    let id = options.id
    let pid = options.pid
    let modelConsole = options.modelConsole || false
    // console.log(type, id, pid)
    this.setData({
      'type':type,
      'id':id,
      'pid':pid,
      'modelConsole': modelConsole
    })
    // this.getPinInfo()
  },

  //得到产品信息
  getPinInfo() {
    let self = this
    // let goodsId = self.data.id
    // let type = self.data.type
    let goodsId = 423
    let type = 'three'

    wx.request({
      url: util.apiUrl + 'xcx.pin.product',
      data: {
        product: goodsId
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: 'POST',
      success: function (res) {
        // console.log(res);
        let error_code = res.data.error_code //错误编码
        let msg = res.data.msg //状态 _ 提示
        //console.log('得到产品信息', res, error_code, msg)//检测数据
        if (error_code == 0) {
          //success
          let product = res.data.product
          console.log(product)
          // self.setData({
          //   'product': res.data.product
          // })
          self.getPorducts(product)
        }
      }
    })
  },
  //获取产品分享图皮
  getPorducts(product) {
    let self = this
    wx.request({
      url: util.apiUrl + 'xcx.pin.pintuan',
      data: {
        id: 60
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: 'POST',
      success: function (res) {
        console.log(res)

        // let type = self.data.type
        let type = 'three'
       
        let Img_product = ''

        if (type == 'three') {
          let tabContentThree = res.data.data['三人拼团']
          // console.log(tabContentThree)
          for (var item of tabContentThree) {
            if (item.goods_id == product.id) {
              // console.log(item.pin_img)
              Img_product = 'https://www.zhenlvw.com/' + item.pin_img
              console.log(Img_product)
              self.setData({
                'Img_product': Img_product
              })
            }
          }
        } else {
          let tabContentPeople = res.data.data['人人拼']
          // console.log(tabContentPeople)
          for (var item of tabContentPeople) {
            if (item.goods_id == product.id) {
              Img_product = 'https://www.zhenlvw.com/' + item.pin_img
              console.log(Img_product)
              self.setData({
                'Img_product': Img_product
              })
            }
          }
        }
       
      }
    })
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    let type = this.data.type
    let id = this.data.id
    let pid = this.data.pid
    let user = wx.getStorageSync('user')
    let userName = user.nickname
    let self = this
    if (res.from === 'button') {
      // 来自页面内转发按钮
    }
    return {
      title: '您的好友(' + userName + ')正在这里买东西，邀请您一起享优惠！',
      path: '/pages/pin_J/pintuan/pintuan?type=' + type + '&shareM=shareYes&id=' + id + '&pid=' + pid,
      imageUrl: self.data.Img_product,
      success: (res) => {
        console.log("转发成功", res);
      },
      fail: (res) => {
        console.log("转发失败", res);
      }
    }
  },
  detailsP(){
    wx.reLaunch({
      url: '../index/index'
    })
  },
  consoleClose(){
    this.setData({
      'modelConsole': !this.data.modelConsole
    })
  },
  consoleOpen(){
    this.setData({
      'modelConsole': !this.data.modelConsole
    })
  },
  //生成分享图片


  wxPeopleQuan(){
    let type = this.data.type
    let id = this.data.id
    let pid = this.data.pid

    //       url: '../wxPeopleQuan/wxPeopleQuan?type=' + 3 + '&id=' + 1 + '&pid=' + 2,
    wx.navigateTo({
      url: '../wxPeopleQuan/wxPeopleQuan?type=' + type + '&id=' + id + '&pid=' + pid

    })
  }
})